package com.autumn.zero.authorization.entitys.users.querys;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Table;

import com.autumn.mybatis.mapper.annotation.ViewTable;
import com.autumn.zero.authorization.entitys.IPermissionEntity;

/**
 * 用户权限查询
 * 
 * @author 杨昌国 2018-12-07 18:02:51
 */
@Table
@ViewTable(UserPermissionQuery.QUERY_COMMAND_TEXT)
public class UserPermissionQuery implements Serializable, IPermissionEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2037260267225169811L;

	/**
	 * 
	 */
	static final String QUERY_COMMAND_TEXT = "SELECT user_id,resources_id,`name`,is_granted FROM sys_user_permission"
			+ " UNION ALL SELECT b.user_id,a.resources_id,a.`name`,a.is_granted FROM sys_role_permission AS a"
			+ " INNER JOIN sys_user_role AS b ON b.role_id = a.role_id";

	/**
	 * 字段 userId
	 */
	public static final String FILED_USER_ID = "userId";

	/**
	 * 用户id
	 */
	private Long userId;

	/**
	 * 资源
	 */
	private String resourcesId;

	/**
	 * 授权名称
	 */
	private String name;

	/**
	 * 是否授权
	 */
	@Column(name = "is_granted", nullable = false)
	private boolean isGranted;

	/**
	 * 获取用户Id
	 * 
	 * @return
	 */
	public Long getUserId() {
		return userId;
	}

	/**
	 * 设置用户Id
	 * 
	 * @param userId 用户Id
	 */
	public void setUserId(Long userId) {
		this.userId = userId;
	}

	/**
	 * 获取资源id
	 * 
	 * @return
	 */
	@Override
	public String getResourcesId() {
		return resourcesId;
	}

	/**
	 * 设置资源id
	 * 
	 * @param resourcesId 资源id
	 */
	@Override
	public void setResourcesId(String resourcesId) {
		this.resourcesId = resourcesId;
	}

	/**
	 * 获取授权名称
	 * 
	 * @return
	 */
	@Override
	public String getName() {
		return name;
	}

	/**
	 * 设置授权名称
	 * 
	 * @param name 授权名称
	 */
	@Override
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 获取是否授权
	 * 
	 * @return
	 */
	@Override
	public boolean getIsGranted() {
		return isGranted;
	}

	/**
	 * 设置是否授权
	 * 
	 * @param isGranted 是否授权
	 */
	@Override
	public void setIsGranted(boolean isGranted) {
		this.isGranted = isGranted;
	}
}
